#!/usr/bin/python

import sys
if(len(sys.argv) != 3):
    print 'ERROR: This script expects 2 arguments.'
    print 'Usage: python cp_file.py <file_id> <dest>'
    sys.exit(1)

import os
from django.core.management import setup_environ
sys.path = ['/var/django/'] + sys.path
from proto_dev import settings
setup_environ(settings)

def file_loc(file_id):
    import bixfile.models
    from bixfile.models import FileUpload
    all_entries = FileUpload.objects.all()
    return all_entries[int(file_id)]

def copy_file(file_id, dest):
    f = file_loc(file_id)
    source = '/var/django/media-dev/' + f.upload
    os.system('cp ' + source + ' ' + dest)
    print 'copying ' + source + ' to ' + dest

copy_file(sys.argv[1], sys.argv[2])

